home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C / Utilities / DVIM72-Mac 1.9.6 / source / option, inch.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-09-14  |  10.9 KB  |  462 lines  |  [TEXT/R*ch]

  1. /**********************************************************************/
  2. /******************************* option *******************************/
  3. /**********************************************************************/
  4. #include <stdlib.h>
  5. #include <math.h>
  6. #include <ctype.h>
  7. #include "dvihead.h"
  8. #include "gendefs.h"
  9. #include "gblprocs.h"
  10. #include "m72.h"
  11. #include "egblvars.h"
  12. #include "mac-specific.h"
  13.  
  14. #if OS_THINKC
  15. #define FATAL Abort_dvi
  16. void Abort_dvi( char *msg );
  17. #else
  18. #define FATAL fatal
  19. #endif
  20.  
  21. void
  22. option(optstr)            /* process command-line option */
  23. char *optstr;            /* option string (e.g. "-m1500") */
  24. {
  25.     register UNSIGN32 k;    /* magnification */
  26.     register int value;        /* converted digit string value */
  27.     register int m;        /* loop index */
  28.     char *p;            /* pointer into optstr */
  29.     int p1,p2,p3;        /* temp values for sscanf() */
  30.     double fltmag;        /* floating-point mag value */
  31.  
  32.     typedef struct
  33.     {
  34.     char* envname;
  35.     char* envvar;
  36.     } envstruct;
  37.  
  38.     static envstruct envlist[] =
  39.     {    /* names and addresses of environment vars (alphabetical order) */
  40.     "DVIHELP",    helpcmd,
  41.     "FONTLIST",    fontlist,
  42.     "TEXFONTS",    fontpath,
  43.     "TEXINPUTS",    subpath,
  44.     };
  45.  
  46.     if (*optstr != '-')
  47.     return;            /* return if this is not an option */
  48.  
  49.     switch (*(optstr+1))
  50.     {
  51.  
  52.     case 'a':    /* A selects virtual font caching */
  53.     case 'A':
  54.  
  55. #if    VIRTUAL_FONTS
  56.     virt_font = TRUE;
  57. #endif
  58.     break;
  59.  
  60.     case 'b':    /* b selects backwards printing order */
  61.     case 'B':
  62.     backwards = TRUE;
  63.     break;
  64.  
  65.  
  66.     case 'c':    /* c selects number of copies */
  67.     case 'C':
  68.     copies = (UNSIGN16) atoi(optstr+2);
  69.     copies = MAX(1,MIN(copies,256)); /* enforce reasonable limits */
  70.     break;
  71.  
  72.  
  73.     case 'd':    /* d selects debug output */
  74.     case 'D':
  75.     debug_code |= (BYTE)atoi(optstr+2);
  76.     break;
  77.  
  78.  
  79.     case 'e':    /* e specifies ``environment'' variable definition */
  80.     case 'E':    /* We ignore letter case since these come from */
  81.         /* the command line */
  82.     if (!(p = strrchr(optstr,'=')))
  83.     {
  84.         /* (void)usage(stderr); */
  85.         (void)sprintf(message,
  86.             "option():  Bad switch [%s]--expected -eENVNAME=value",
  87.         optstr);
  88.         (void)FATAL(message);
  89.     }
  90.     *p = '\0';        /* clobber "=" by string terminator */
  91.     for (m = 0; m < sizeof(envlist)/sizeof(envlist[0]); ++m)
  92.     {
  93.         if (strcm2(optstr+2,envlist[m].envname) == 0)
  94.         {
  95.         (void)strcpy(envlist[m].envvar,p+1);
  96.         return;
  97.         }
  98.     }
  99.     /* (void)usage(stderr); */
  100.  
  101.     (void)sprintf(message,"option():  Bad switch [%s]--expected one of:",
  102.         optstr);
  103.     for (m = 0; m < sizeof(envlist)/sizeof(envlist[0]); ++m)
  104.     {
  105.         (void)strcat(message," ");
  106.         (void)strcat(message,envlist[m].envname);
  107.     }
  108.     (void)FATAL(message);
  109.     break;
  110.  
  111.  
  112.     case 'f':    /* f specifies font substitution file */
  113.     case 'F':
  114.     (void)strcpy(subfile,optstr+2);
  115.     break;
  116.  
  117.  
  118. #if    CANON_A2
  119.  
  120. #ifdef CANON_TEST
  121.     case 'g':
  122.     case 'G':
  123.         stor_fonts = (UNSIGN32)atoi(optstr + 2 );
  124.         break;
  125. #endif /* CANON_TEST */
  126.  
  127. #endif
  128.  
  129.     case 'l':    /* l prohibits logging of errors */
  130.     case 'L':
  131.     g_dolog = FALSE;
  132.     break;
  133.  
  134.  
  135.     case 'm':    /* m selects alternate magnification */
  136.     case 'M':
  137.     /* Collect 2*value initially.  Then if value is small, assume
  138.     user specified magstep value; magstep k means 1.2**k, where k
  139.     is integral, or half-integral.  Otherwise, assume user has
  140.     specified pxl file magnification (1000 == 200dpi, 1500 ==
  141.     300dpi, etc.).  */
  142.  
  143.  
  144.     if (strchr(optstr+2,'.') != (char *)NULL)
  145.         fltmag = (double)(2.0 * atof(optstr+2));
  146.     else
  147.         fltmag = (double)(2 * atoi(optstr+2));
  148.     if ((0.0 != fltmag) && 
  149.         (-30.0 <= fltmag) && (fltmag <= 30.0)) /* magstep 15 is limit */
  150.     {
  151.         if (fltmag < 0.0)
  152.             runmag = (UNSIGN32)(0.5 + 
  153.             (1.0/pow((double)sqrt(1.2),-fltmag))*(double)STDMAG);
  154.         else
  155.             runmag = (UNSIGN32)(0.5 + pow((double)sqrt(1.2),fltmag)*
  156.                 (double)STDMAG);
  157.     }
  158.     else
  159.         runmag = (UNSIGN32)(0.5 + fltmag/2.0);
  160.  
  161.     k = MAGSIZE(actfact_res(runmag));  /* rounded magnification */
  162.     if (k != runmag)
  163.     {
  164.         (void)sprintf(message,
  165.         "option():  Requested magnification %d not available.",
  166.         (int)runmag);
  167.         (void)warning(message);
  168.         runmag = k;
  169.         k = (UNSIGN32) MAX(1,MIN(mag_index,(MAGTABSIZE-1)));
  170.         (void)sprintf(message,
  171.         "  Magnification reset to nearest legal value %d in \
  172. family ..%d..%d..%d..",
  173.         (int)runmag,(int)MAGSIZE(mag_table[k-1]),
  174.         (int)MAGSIZE(mag_table[k]),
  175.         (int)MAGSIZE(mag_table[k+1]));
  176.         (void)warning(message);
  177.     }
  178.     break;
  179.  
  180.  
  181.     case 'o':
  182.     case 'O':    /* o selects output page range (-o# or -o#:# or -o#:#:#) */
  183.         p1 = p2 = p3 = 0;
  184.     value = (int)sscanf(optstr+2,"%d:%d:%d",&p1,&p2,&p3);
  185.     page_begin[npage] = p1;
  186.     page_end[npage] = p2;
  187.     page_step[npage] = p3;
  188.     switch (value)
  189.     {
  190.     case 1:
  191.         optstr++;            /* point past "-" */
  192.  
  193.         do                /* skip over digit string */
  194.         {
  195.         optstr++;
  196.         }
  197.         while (isdigit(*optstr) || (*optstr == '-') || (*optstr == '+'));
  198.  
  199.         if (*optstr)        /* trash follows number */
  200.         {
  201.             /* (void)usage(stderr); */
  202.         (void)sprintf(message,
  203.             "option():  %s is not a legal page number switch",optstr);
  204.         (void)FATAL(message);
  205.         }
  206.         else            /* had expected end-of-string */
  207.             page_end[npage] = (INT16)page_begin[npage];
  208.         page_step[npage] = 1;
  209.         break;
  210.  
  211.     case 2:        /* supply default step */
  212.         page_step[npage] = 1;
  213.         /* FALL THROUGH to case 3 for order check */
  214.  
  215.     case 3:        /* check for positive step */
  216.         page_step[npage] = ABS(page_step[npage]);
  217.         if (page_step[npage] == 0)
  218.         page_step[npage] = 1;
  219.         break;
  220.  
  221.     default:    /* illegal value */
  222.         /* (void)usage(stderr); */
  223.         (void)sprintf(message,
  224.         "option():  %s is not a legal page number switch",optstr);
  225.         (void)FATAL(message);
  226.     }
  227.     npage++;
  228.     break;
  229.  
  230.  
  231.     case 'p':    /* p prohibits pre-font loading */
  232.     case 'P':
  233. #if (OS_THINKC|HPLASERJET|HPJETPLUS|GOLDENDAWNGL100|POSTSCRIPT|IMPRESS|CANON_A2)
  234.     preload = TRUE;    /* preloading required for Canon engines */
  235.             /* because of reverse printing order */
  236. #else
  237.     preload = FALSE;
  238. #endif /*NOT(HPLASERJET|HPJETPLUS|GOLDENDAWNGL100|POSTSCRIPT|IMPRESS|CANON_A2)*/
  239.     break;
  240.  
  241.  
  242.     case 'q':    /* q inhibits status display */
  243.     case 'Q':
  244.     quiet = TRUE;
  245.     break;
  246.  
  247.  
  248. #if    HPLASERJET
  249.     case 'r':    /* r selects output resolution */
  250.     case 'R':
  251.     hpres = (INT16)atoi(optstr+2);
  252.     if ((hpres != 75) && (hpres != 100) && (hpres != 150) &&
  253.         (hpres != 300))
  254.         {
  255.         (void)sprintf(message,
  256.         "option():  Output resolution not in [75,100,150,300] dpi; \
  257. reset to %d",
  258.         DEFAULT_RESOLUTION);
  259.         (void)warning(message);
  260.         hpres = DEFAULT_RESOLUTION;
  261.         }
  262.     break;
  263. #endif /* HPLASERJET */
  264.  
  265.  
  266. #if    (APPLEIMAGEWRITER | EPSON | GOLDENDAWNGL100 | TOSHIBAP1351)
  267.     case 'r':    /* r selects run-length coding of output */
  268.     case 'R':
  269.     runlengthcode = TRUE;
  270.     break;
  271. #endif /* (APPLEIMAGEWRITER | EPSON | GOLDENDAWNGL100 | TOSHIBAP1351) */
  272.  
  273.  
  274. #if    CANON_A2
  275.  
  276. #ifdef CANON_TEST
  277.     case 's':    /* pixel size limit to force character reloading */
  278.     case 'S':
  279.     size_limit = (UNSIGN16)atoi(optstr+2);
  280.     break;
  281. #endif /* CANON_TEST */
  282.  
  283. #endif /* CANON_A2 */
  284.  
  285. #if    POSTSCRIPT
  286.     case 's':    /* pixel size limit to force character reloading */
  287.     case 'S':
  288.     size_limit = (UNSIGN16)atoi(optstr+2);
  289.     break;
  290. #endif
  291.  
  292. #if    EPSON
  293.     case 't':
  294.     case 'T':
  295.  
  296. #if    HIRES
  297.     twice_a_line = TRUE;
  298. #endif /* HIRES */
  299.  
  300.     break;
  301. #endif /* EPSON */
  302.  
  303.  
  304. #if    CANON_A2
  305.  
  306. #ifdef CANON_TEST
  307.     case 'u':
  308.     case 'U':
  309.     merit_fact = (UNSIGN16)atoi(optstr+2);
  310.     break;
  311.  
  312.     case 'v':
  313.     case 'V':
  314.     stor_limit = (UNSIGN32)atoi(optstr+2);
  315.     break;
  316. #endif /* CANON_TEST */
  317.  
  318. #endif /* CANON_A2 */
  319.  
  320. #if    POSTSCRIPT
  321.     case 'v':    /* vmbug -- reload fonts on each page */
  322.     case 'V':
  323.     ps_vmbug = TRUE;
  324.     break;
  325. #endif /* POSTSCRIPT */
  326.  
  327.  
  328.     case 'x':
  329.     case 'X':
  330.     leftmargin = inch(optstr+2);
  331.     break;
  332.  
  333.  
  334.     case 'y':
  335.     case 'Y':
  336.     topmargin = inch(optstr+2);
  337.     break;
  338.  
  339. #if    (OS_TOPS20 | BSD42)
  340.     case 'z':
  341.     case 'Z':
  342.     spool_output = TRUE;    /* offer to send output to spooler */
  343.     break;
  344. #endif /* (OS_TOPS20 | BSD42) */
  345.  
  346.     default:
  347.     /* (void)usage(stderr); */
  348.     (void)sprintf(message,"option():  %s is not a legal switch", optstr);
  349.     (void)FATAL(message);
  350.     }
  351. }
  352.  
  353. /**********************************************************************/
  354. /******************************** inch ********************************/
  355. /**********************************************************************/
  356. float
  357. inch(s)
  358. char *s;
  359.  
  360. /***********************************************************************
  361. Convert a value field in s[] of the form
  362.  
  363.     ------        ------------------------------
  364.     value            units implied
  365.     ------        ------------------------------
  366.     #.##bp        big point (1in = 72bp)
  367.     #.##cc        cicero (1cc = 12dd)
  368.     #.##cm        centimeter
  369.     #.##dd        didot point (1157dd = 1238pt)
  370.     #.##in        inch
  371.     #.##mm        millimeter (10mm = 1cm)
  372.     #.##pc        pica (1pc = 12pt)
  373.     #.##pt        point (72.27pt = 1in)
  374.     #.##sp        scaled point (65536sp = 1pt)
  375.     ------        ------------------------------
  376.  
  377. to inches, returning it as the function value.  A leading plus or  minus
  378. sign is optional.  The letter case of the dimension name is ignored.  No
  379. space is permitted between the number and the dimension.
  380. ***********************************************************************/
  381.  
  382. {
  383.     BOOLEAN neg;
  384.     register char *tc;
  385.     register double flnum, pten;
  386.  
  387.     flnum = 0.0;
  388.     tc = s;
  389.     neg = FALSE;
  390.  
  391.     if (*tc == '-')
  392.     {
  393.     ++tc;
  394.     neg = TRUE;
  395.     }
  396.     else if (*tc == '+')
  397.     {
  398.     ++tc;
  399.     neg = FALSE;
  400.     }
  401.  
  402.     /* we do not use sprintf() here because we want to be able to easily
  403.     find the dimension string */
  404.  
  405.     for (; isdigit(*tc); ++tc)    /* collect integer part */
  406.     flnum = flnum*10.0 + (double)((*tc) - '0');
  407.  
  408.     if (*tc == '.')            /* collect fractional part */
  409.     for ((pten = 10.0, ++tc); isdigit(*tc); (pten *= 10.0,++tc))
  410.         flnum += ((double)((*tc) - '0'))/pten;
  411.  
  412.     if (strcm2(tc,"in") == 0)        /* inches */
  413.     ;
  414.     else if (strcm2(tc,"cm") == 0)    /* centimeters */
  415.     flnum /= 2.54;
  416.     else if (strcm2(tc,"pt") == 0)    /* points */
  417.     flnum /= 72.27;
  418.     else if (strcm2(tc,"bp") == 0)    /* big points */
  419.     flnum /= 72.0;
  420.     else if (strcm2(tc,"cc") == 0)    /* cicero */
  421.     flnum *= 12.0 * (1238.0 / 1157.0) / 72.27;
  422.     else if (strcm2(tc,"dd") == 0)    /* didot points */
  423.     flnum *= (1238.0 / 1157.0) / 72.27;
  424.     else if (strcm2(tc,"mm") == 0)    /* millimeters */
  425.     flnum /= 25.4;
  426.     else if (strcm2(tc,"pc") == 0)    /* pica */
  427.     flnum *= 12.0 / 72.27;
  428.     else if (strcm2(tc,"sp") == 0)    /* scaled points */
  429.     flnum /= (65536.0 * 72.27);
  430.     else                /* unknown units -- error */
  431.  
  432. #if    PXLID                            /* must be in DVI driver */
  433.     {
  434.     (void)sprintf(message,
  435.         "inch():  Unrecognized dimension string [%s];\nexpected one of \
  436. bp, cc, cm, dd, in, mm, pc, pt or sp\n",s);
  437.         (void)FATAL(message);
  438.     }
  439. #else                                   /* some other program then */
  440.     {
  441.         (void)printf("inch():  Unrecognized dimension string [%s];",s);
  442.     printf("\n");
  443.     (void)printf(
  444.         "expected one of bp, cc, cm, dd, in, mm, pc, pt or sp");
  445.     printf("\n");
  446.         EXIT(1);
  447.     }
  448. #endif
  449.  
  450.     if (neg)
  451.     flnum = -flnum;
  452.     return((float)flnum);
  453. }
  454.  
  455. /* ---------------------------- Abort_dvi ---------------------------- */
  456. void
  457. Abort_dvi( char *msg )
  458. {
  459.     g_abort_dvi = TRUE;
  460.     Show_error( msg );
  461. }
  462.